using System;
using System.Collections.Generic;
using System.Text;

namespace SqlTools.DataAccessLibrary
{
	public abstract class PrimaryKey : IEquatable<PrimaryKey>
	{
		private Dictionary<string, object> _columns = new Dictionary<string, object>();

		public Dictionary<string, object> Columns
		{
			get { return _columns; }
		}

		public object this[string name]
		{
			get
			{
				if ( _columns.ContainsKey(name) )
					return _columns[name];

				return null;
			}
			set
			{
				if ( _columns.ContainsKey(name) )
					_columns[name] = value;
			}
		}

		#region IEquatable<PrimaryKey> Members

		public bool Equals(PrimaryKey other)
		{
			if ( this._columns.Count != other._columns.Count )
				return false;

			foreach ( KeyValuePair<string, object> kvp in _columns )
			{
				if ( !other._columns.ContainsKey(kvp.Key) )
					return false;

				if ( other._columns[kvp.Key] != kvp.Value )
					return false;
			}

			return true;
		}

		#endregion

		#region IEquatable<PrimaryKey> Members

		bool IEquatable<PrimaryKey>.Equals(PrimaryKey other)
		{
			if ( this._columns.Count != other._columns.Count )
				return false;

			foreach ( KeyValuePair<string, object> kvp in _columns )
			{
				if ( !other._columns.ContainsKey(kvp.Key) )
					return false;

				if ( other._columns[kvp.Key] != kvp.Value )
					return false;
			}

			return true;
		}

		#endregion

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}
}
